<?php
/**
 * Created by PhpStorm.
 * User: kun
 * Date: 26/6/19
 * Time: 21:35
 */

namespace app\common\lib\exception;

use Exception;
use think\exception\Handle;

class ApiHandleException extends Handle
{
    /**
     * http 状态码
     * @var int
     */
    public $httpCode = 500;

    public function render(\Exception $e)
    {
        if (config('app_debug') == true) {
            //调用父级render()方法
            return parent::render($e);
        }
        if ($e instanceof ApiException) {
            $this->httpCode = $e->httpCode;
        }
       
        return show(0, $e->getMessage(), [], $this->httpCode);
    }
}